package com.ruoyi.loan.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.AliyunOssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.loan.domain.TbLoan;
import com.ruoyi.loan.service.ITbLoanService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 贷款申请Controller
 * 
 * @author jy
 * @date 2023-01-16
 */
@Api(tags = "Loan-Api")
@RestController
@RequestMapping("/loan")
public class TbLoanController extends BaseController
{
    @Autowired
    private ITbLoanService tbLoanService;

    /**
     * 查询贷款申请列表
     */
    @ApiOperation("贷款列表")
    @RequiresPermissions("loan:loan:list")
    @GetMapping("/list")
    public TableDataInfo list(TbLoan tbLoan)
    {
        startPage();
        List<TbLoan> list = tbLoanService.selectTbLoanList(tbLoan);
        return getDataTable(list);
    }

    /**
     * 导出贷款申请列表
     */
    @ApiOperation("导出贷款列表")
    @RequiresPermissions("loan:loan:export")
    @Log(title = "贷款申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbLoan tbLoan)
    {
        List<TbLoan> list = tbLoanService.selectTbLoanList(tbLoan);
        ExcelUtil<TbLoan> util = new ExcelUtil<TbLoan>(TbLoan.class);
        util.exportExcel(response, list, "贷款申请数据");
    }

    /**
     * 获取贷款申请详细信息
     */
    @ApiOperation("获取贷款详细信息")
    @RequiresPermissions("loan:loan:query")
    @GetMapping(value = "/getLoan/{loanId}")
    public AjaxResult getInfo(@PathVariable("loanId") Long loanId)
    {
        return success(tbLoanService.selectTbLoanByLoanId(loanId));
    }

    /**
     * 新增贷款申请
     */
    @ApiOperation("新增贷款申请")
    @RequiresPermissions("loan:loan:add")
    @Log(title = "贷款申请", businessType = BusinessType.INSERT)
    @PostMapping("/addLoan")
    public AjaxResult add(@RequestBody TbLoan tbLoan)
    {
        return toAjax(tbLoanService.insertTbLoan(tbLoan));
    }

    /**
     * 修改贷款申请
     */
    @ApiOperation("修改贷款申请")
    @RequiresPermissions("loan:loan:edit")
    @Log(title = "贷款申请", businessType = BusinessType.UPDATE)
    @PutMapping("/updateLoan")
    public AjaxResult edit(@RequestBody TbLoan tbLoan)
    {
        return toAjax(tbLoanService.updateTbLoan(tbLoan));
    }

    /**
     * 删除贷款申请
     */
    @ApiOperation("删除贷款申请")
    @RequiresPermissions("loan:loan:remove")
    @Log(title = "贷款申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/delLoan/{loanIds}")
    public AjaxResult remove(@PathVariable Long[] loanIds)
    {
        return toAjax(tbLoanService.deleteTbLoanByLoanIds(loanIds));
    }

}
